﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SkeletonNET.Crud.Repository;
using SkeletonNET.Crud;
using System.Data.Entity;
using System.Linq.Expressions;

namespace SkeletonNET.Base.Crud.CrudManager
{
    public interface ICrudManager<TEntity>
        where TEntity : class, IEntity, new()
    {
        /// <summary>
        /// Update an existing entity
        /// </summary>
        /// <param name="entity">The entity to update.</param>
        /// <returns>Reference to the updated entity</returns>
        TEntity Update(TEntity entity);
        /// <summary>
        /// Delete an existing entity
        /// </summary>
        /// <param name="entity">The entity to delete.</param>
        void Delete(TEntity entity);
        /// <summary>
        /// Delete an existing entity by its id.
        /// </summary>
        /// <param name="id">The id of the entity to delete.</param>
        void DeleteByID(object id);
        /// <summary>
        /// Insert a new entity.
        /// </summary>
        /// <param name="entity">The entity to insert.</param>
        /// <returns>Reference to the inserted entity.</returns>
        TEntity Insert(TEntity entity);
        /// <summary>
        /// Get all entities
        /// </summary>
        /// <returns>IEnumerable containing types of TEntity</returns>
        IEnumerable<TEntity> All(Expression<Func<TEntity, bool>> expr = null);
        /// <summary>
        /// Get an entity by its id
        /// </summary>
        /// <param name="id">ID of the entity</param>
        /// <returns>Reference to the found entity or null if none</returns>
        TEntity GetByID(object id);
        TEntity InsertOrUpdate(TEntity entity);
        void Save();
    }
}
